<!DOCTYPE html>

<html>
<head>
<meta content="text/html; charset=utf-8" http-equiv="Content-Type">

<title>class StoreController - Rails Application Documentation</title>

<link type="text/css" media="screen" href="./rdoc.css" rel="stylesheet">

<script type="text/javascript">
  var rdoc_rel_prefix = "./";
</script>

<script type="text/javascript" charset="utf-8" src="./js/jquery.js"></script>
<script type="text/javascript" charset="utf-8" src="./js/navigation.js"></script>
<script type="text/javascript" charset="utf-8" src="./js/search_index.js"></script>
<script type="text/javascript" charset="utf-8" src="./js/search.js"></script>
<script type="text/javascript" charset="utf-8" src="./js/searcher.js"></script>
<script type="text/javascript" charset="utf-8" src="./js/darkfish.js"></script>


<body id="top" class="class">
<nav id="metadata">
  <nav id="home-section" class="section">
  <h3 class="section-header">
    <a href="./index.html">Home</a>
    <a href="./table_of_contents.html#classes">Classes</a>
    <a href="./table_of_contents.html#methods">Methods</a>
  </h3>
</nav>


  <nav id="search-section" class="section project-section" class="initially-hidden">
  <form action="#" method="get" accept-charset="utf-8">
    <h3 class="section-header">
      <input type="text" name="search" placeholder="Search" id="search-field"
             title="Type to search, Up and Down to navigate, Enter to load">
    </h3>
  </form>

  <ul id="search-results" class="initially-hidden"></ul>
</nav>


  <div id="file-metadata">
    <nav id="file-list-section" class="section">
  <h3 class="section-header">Defined In</h3>
  <ul>
    <li>app/controllers/store_controller.rb
  </ul>
</nav>

    
  </div>

  <div id="class-metadata">
    
    <nav id="parent-class-section" class="section">
  <h3 class="section-header">Parent</h3>
  
  <p class="link"><a href="ApplicationController.html">ApplicationController</a>
  
</nav>

    
    <!-- Method Quickref -->
<nav id="method-list-section" class="section">
  <h3 class="section-header">Methods</h3>

  <ul class="link-list">
    
    <li><a href="#method-i-add_to_cart">#add_to_cart</a>
    
    <li><a href="#method-i-authorize">#authorize</a>
    
    <li><a href="#method-i-checkout">#checkout</a>
    
    <li><a href="#method-i-empty_cart">#empty_cart</a>
    
    <li><a href="#method-i-index">#index</a>
    
    <li><a href="#method-i-save_order">#save_order</a>
    
  </ul>
</nav>

  </div>

  <div id="project-metadata">
    <nav id="fileindex-section" class="section project-section">
  <h3 class="section-header">Pages</h3>

  <ul>
  
    <li class="file"><a href="./doc/README_FOR_APP.html">README_FOR_APP</a>
  
  </ul>
</nav>

    <nav id="classindex-section" class="section project-section">
  <h3 class="section-header">Class and Module Index</h3>

  <ul class="link-list">
  
    <li><a href="./AdminController.html">AdminController</a>
  
    <li><a href="./AdminHelper.html">AdminHelper</a>
  
    <li><a href="./ApplicationController.html">ApplicationController</a>
  
    <li><a href="./ApplicationHelper.html">ApplicationHelper</a>
  
    <li><a href="./Cart.html">Cart</a>
  
    <li><a href="./CartItem.html">CartItem</a>
  
    <li><a href="./InfoController.html">InfoController</a>
  
    <li><a href="./InfoHelper.html">InfoHelper</a>
  
    <li><a href="./LineItem.html">LineItem</a>
  
    <li><a href="./LineItemsController.html">LineItemsController</a>
  
    <li><a href="./LineItemsHelper.html">LineItemsHelper</a>
  
    <li><a href="./Order.html">Order</a>
  
    <li><a href="./OrdersController.html">OrdersController</a>
  
    <li><a href="./OrdersHelper.html">OrdersHelper</a>
  
    <li><a href="./Product.html">Product</a>
  
    <li><a href="./ProductsController.html">ProductsController</a>
  
    <li><a href="./ProductsHelper.html">ProductsHelper</a>
  
    <li><a href="./StoreController.html">StoreController</a>
  
    <li><a href="./StoreHelper.html">StoreHelper</a>
  
    <li><a href="./User.html">User</a>
  
    <li><a href="./UsersController.html">UsersController</a>
  
    <li><a href="./UsersHelper.html">UsersHelper</a>
  
  </ul>
</nav>

  </div>
</nav>

<div id="documentation">
  <h1 class="class">class StoreController</h1>

  <div id="description" class="description">
    
  </div><!-- description -->

  
  
  
  <section id="5Buntitled-5D" class="documentation-section">
    

    

    

    

    <!-- Methods -->
    
     <section id="public-instance-5Buntitled-5D-method-details" class="method-section section">
      <h3 class="section-header">Public Instance Methods</h3>

    
      <div id="method-i-add_to_cart" class="method-detail ">
        
        <div class="method-heading">
          <span class="method-name">add_to_cart</span><span
            class="method-args">()</span>
          <span class="method-click-advice">click to toggle source</span>
        </div>
        

        <div class="method-description">
          
          
          

          
          <div class="method-source-code" id="add_to_cart-source">
            <pre><span class="ruby-comment"># File app/controllers/store_controller.rb, line 10</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier">add_to_cart</span>
  <span class="ruby-identifier">product</span> = <span class="ruby-constant">Product</span>.<span class="ruby-identifier">find</span>(<span class="ruby-identifier">params</span>[<span class="ruby-value">:id</span>]) 
  <span class="ruby-comment">#@cart = find_cart </span>
  <span class="ruby-ivar">@current_item</span> = <span class="ruby-ivar">@cart</span>.<span class="ruby-identifier">add_product</span>(<span class="ruby-identifier">product</span>)
  <span class="ruby-identifier">respond_to</span> <span class="ruby-keyword">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">format</span><span class="ruby-operator">|</span>
    <span class="ruby-identifier">format</span>.<span class="ruby-identifier">js</span> <span class="ruby-keyword">if</span> <span class="ruby-identifier">request</span>.<span class="ruby-identifier">xhr?</span>
    <span class="ruby-identifier">format</span>.<span class="ruby-identifier">html</span> {<span class="ruby-identifier">redirect_to_index</span>}
  <span class="ruby-keyword">end</span>
  <span class="ruby-keyword">rescue</span> <span class="ruby-constant">ActiveRecord</span><span class="ruby-operator">::</span><span class="ruby-constant">RecordNotFound</span>
  <span class="ruby-identifier">logger</span>.<span class="ruby-identifier">error</span>(<span class="ruby-node">&quot;Attempt to access invalid product #{params[:id]}&quot;</span>)
  <span class="ruby-identifier">flash</span>[<span class="ruby-value">:notice</span>] = <span class="ruby-string">&quot;Invalid product&quot;</span>
  <span class="ruby-identifier">redirect_to_index</span>(<span class="ruby-string">&quot;Invalid product&quot;</span>)
<span class="ruby-keyword">end</span></pre>
          </div><!-- add_to_cart-source -->
          
        </div>

        

        
      </div><!-- add_to_cart-method -->

    
      <div id="method-i-checkout" class="method-detail ">
        
        <div class="method-heading">
          <span class="method-name">checkout</span><span
            class="method-args">()</span>
          <span class="method-click-advice">click to toggle source</span>
        </div>
        

        <div class="method-description">
          
          
          

          
          <div class="method-source-code" id="checkout-source">
            <pre><span class="ruby-comment"># File app/controllers/store_controller.rb, line 29</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier">checkout</span>
  <span class="ruby-comment">#@cart = find_cart</span>
  <span class="ruby-keyword">if</span> <span class="ruby-ivar">@cart</span>.<span class="ruby-identifier">items</span>.<span class="ruby-identifier">empty?</span>
    <span class="ruby-identifier">redirect_to_index</span>(<span class="ruby-string">&quot;Your cart is empty&quot;</span>)
  <span class="ruby-keyword">else</span>
    <span class="ruby-ivar">@order</span> = <span class="ruby-constant">Order</span>.<span class="ruby-identifier">new</span>
  <span class="ruby-keyword">end</span>
<span class="ruby-keyword">end</span></pre>
          </div><!-- checkout-source -->
          
        </div>

        

        
      </div><!-- checkout-method -->

    
      <div id="method-i-empty_cart" class="method-detail ">
        
        <div class="method-heading">
          <span class="method-name">empty_cart</span><span
            class="method-args">()</span>
          <span class="method-click-advice">click to toggle source</span>
        </div>
        

        <div class="method-description">
          
          
          

          
          <div class="method-source-code" id="empty_cart-source">
            <pre><span class="ruby-comment"># File app/controllers/store_controller.rb, line 24</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier">empty_cart</span>
  <span class="ruby-identifier">session</span>[<span class="ruby-value">:cart</span>] = <span class="ruby-keyword">nil</span>
  <span class="ruby-identifier">redirect_to_index</span>
<span class="ruby-keyword">end</span></pre>
          </div><!-- empty_cart-source -->
          
        </div>

        

        
      </div><!-- empty_cart-method -->

    
      <div id="method-i-index" class="method-detail ">
        
        <div class="method-heading">
          <span class="method-name">index</span><span
            class="method-args">()</span>
          <span class="method-click-advice">click to toggle source</span>
        </div>
        

        <div class="method-description">
          
          
          

          
          <div class="method-source-code" id="index-source">
            <pre><span class="ruby-comment"># File app/controllers/store_controller.rb, line 5</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier">index</span>
  <span class="ruby-ivar">@products</span> = <span class="ruby-constant">Product</span>.<span class="ruby-identifier">find_products_for_sale</span>
  <span class="ruby-comment">#@cart = find_cart</span>
<span class="ruby-keyword">end</span></pre>
          </div><!-- index-source -->
          
        </div>

        

        
      </div><!-- index-method -->

    
      <div id="method-i-save_order" class="method-detail ">
        
        <div class="method-heading">
          <span class="method-name">save_order</span><span
            class="method-args">()</span>
          <span class="method-click-advice">click to toggle source</span>
        </div>
        

        <div class="method-description">
          
          
          

          
          <div class="method-source-code" id="save_order-source">
            <pre><span class="ruby-comment"># File app/controllers/store_controller.rb, line 38</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier">save_order</span>
  <span class="ruby-comment">#@cart = find_cart</span>
  <span class="ruby-ivar">@order</span> = <span class="ruby-constant">Order</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">params</span>[<span class="ruby-value">:order</span>]) <span class="ruby-comment"># &lt;label id=&quot;code.p.new.order&quot;/&gt;</span>
  <span class="ruby-ivar">@order</span>.<span class="ruby-identifier">add_line_items_from_cart</span>(<span class="ruby-ivar">@cart</span>) <span class="ruby-comment"># &lt;label id=&quot;code.p.append.li&quot;/&gt;</span>
  <span class="ruby-keyword">if</span> <span class="ruby-ivar">@order</span>.<span class="ruby-identifier">save</span>                     <span class="ruby-comment"># &lt;label id=&quot;code.p.save&quot;/&gt;</span>
    <span class="ruby-identifier">session</span>[<span class="ruby-value">:cart</span>] = <span class="ruby-keyword">nil</span>
    <span class="ruby-identifier">redirect_to_index</span>(<span class="ruby-string">&quot;Thank you for your order&quot;</span>)
  <span class="ruby-keyword">else</span>
    <span class="ruby-identifier">render</span> <span class="ruby-value">:action</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-string">'checkout'</span>
  <span class="ruby-keyword">end</span>
<span class="ruby-keyword">end</span></pre>
          </div><!-- save_order-source -->
          
        </div>

        

        
      </div><!-- save_order-method -->

    
    </section><!-- public-instance-method-details -->
  
     <section id="protected-instance-5Buntitled-5D-method-details" class="method-section section">
      <h3 class="section-header">Protected Instance Methods</h3>

    
      <div id="method-i-authorize" class="method-detail ">
        
        <div class="method-heading">
          <span class="method-name">authorize</span><span
            class="method-args">()</span>
          <span class="method-click-advice">click to toggle source</span>
        </div>
        

        <div class="method-description">
          
          
          

          
          <div class="method-source-code" id="authorize-source">
            <pre><span class="ruby-comment"># File app/controllers/store_controller.rb, line 63</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier">authorize</span>
<span class="ruby-keyword">end</span></pre>
          </div><!-- authorize-source -->
          
        </div>

        

        
      </div><!-- authorize-method -->

    
    </section><!-- protected-instance-method-details -->
  
  </section><!-- 5Buntitled-5D -->

</div><!-- documentation -->


<footer id="validator-badges">
  <p><a href="http://validator.w3.org/check/referer">[Validate]</a>
  <p>Generated by <a href="https://github.com/rdoc/rdoc">RDoc</a> 3.12.
  <p>Generated with the <a href="http://deveiate.org/projects/Darkfish-Rdoc/">Darkfish Rdoc Generator</a> 3.
</footer>

